/**
 * 
 */
package adnotatio.server.impl;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletConfig;

import adnotatio.common.data.IPropertiesContainer;
import adnotatio.server.IAnnotationProvider;

/**
 * @author kotelnikov
 */
public class AnnotationProvider extends Provider implements IAnnotationProvider {

    private List<IPropertiesContainer> fList;

    /**
     * @param config
     */
    public AnnotationProvider(ServletConfig config) {
        super(config);
    }

    /**
     * @see adnotatio.server.IAnnotationProvider#getContent(java.lang.String)
     */
    public String getContent(String docId) throws IOException {
        return readResource("HtmlAnnotator-content.xml");
    }

    /**
     * @see adnotatio.server.IAnnotationProvider#loadAnnotations(java.lang.String)
     */
    public List<IPropertiesContainer> loadAnnotations(String docId)
        throws IOException {
        if (fList == null) {
            fList = readPropertiesContainerList("HtmlAnnotator-annotations.xml");
        }
        return fList;
    }

    /**
     * @see adnotatio.server.IAnnotationProvider#storeAnnotations(java.lang.String,
     *      java.util.List)
     */
    public List<IPropertiesContainer> storeAnnotations(
        String docId,
        List<IPropertiesContainer> annotations) throws IOException {
        List<IPropertiesContainer> list = loadAnnotations(docId);
        list.addAll(0, annotations);
        return annotations;
    }

}
